package com.hao.tool.common.util;

import org.apache.commons.lang3.StringUtils;

/**
 * description
 *
 * @author sawyerlsy
 * @date 2019-09-26
 * @since
 */
public class SystemPropertyUtil {

    /**
     * 解析 args,将args属性设置为系统环境变量
     */
    public static void argsToSystemProperty(String[] args) {
        if (null != args && args.length > 0) {
            for (int i = 0; i < args.length; i++) {
                final String tempArg = args[0];
                if (StringUtils.isBlank(tempArg)) {
                    continue;
                }

                //根据=进行分割,如果长度不为2则跳过
                final String[] argArray = tempArg.split("=");
                if (argArray.length != 2) {
                    continue;
                }

                final String propertyName = argArray[0];
                final String propertyVal = argArray[1];
                System.setProperty(propertyName, propertyVal);
                System.out.println("receive the arg:" + tempArg + " ==> name=" + propertyName + ",value=" + propertyVal);
            }
        }
    }
}
